﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Housing;
using System.Data.SqlClient;

public partial class HouseKeep_AreaCheck : System.Web.UI.Page
{
    Apply apply = new Apply();
    protected void Page_Load(object sender, EventArgs e)
    {
        int peoplenum = 1;             //家庭总人口
        int ispronum = 1;              //保障人口数
        float totlearea = 0;           //家庭建筑面积
        float avgarea = 0;             //人均建筑面积
        float otherrentstandard = 1;   //租金补贴标准(最低收入、其他家庭)
        float lowrentstandard = 1;     //租金补贴标准(低收入)
        float onlyonearea = 0;         //租金补贴户面积（36㎡）
        float homeavgarea = 0;         //租金补贴比较面积(18㎡)
        float standardlowarea = 1;     //保障面积最低标准(5㎡)
        if (Request["id"] != null)
        {
            SqlDataReader dr = apply.GetApplyForCheckByNoid(Request.QueryString["id"].ToString());
            if (dr.Read())
            {
                txbpeoplenum.Text = dr["apply_peoplenum"].ToString();
                txbispronum.Text = dr["c"].ToString();
                txbarea.Text = dr["apply_totlearea"].ToString();
                txbavgarea.Text = dr["apply_avgarea"].ToString();
                totlearea = float.Parse(dr["apply_totlearea"].ToString());
                avgarea = float.Parse(dr["apply_avgarea"].ToString());
                ispronum = Convert.ToInt32(dr["c"].ToString());
                peoplenum = Convert.ToInt32(dr["apply_peoplenum"].ToString());
                lblnoid.Text = dr["apply_noid"].ToString();
            }
            dr.Close();
            SystemItems systemitem = new SystemItems();
            systemitem.GetNewestSystemItem();
            if (systemitem != null)
            {
                otherrentstandard = float.Parse(systemitem.Sys_otherrentstandard);
                lowrentstandard = float.Parse(systemitem.Sys_lowrentstandard);
                onlyonearea = float.Parse(systemitem.Sys_onlyonearea);
                homeavgarea = float.Parse(systemitem.Sys_avgarea);
                standardlowarea = float.Parse(systemitem.Sys_standardlowarea);
            }
            Documents document = new Documents();
            string doctype = document.GetDocTypeByNoid(lblnoid.Text);//保障类型（最低收入家庭，低收入家庭，其他家庭）
            SubsidyRecord subsidyrecord = new SubsidyRecord();
            subsidyrecord.GetNewestSubsidyRecordByNoid(lblnoid.Text);
            if (subsidyrecord.Adj_stoptime != null)
            {
                float subarea = 0;
                float submoney = 0;
                if (peoplenum == 1)
                {
                    subarea = onlyonearea - totlearea;
                    if (subarea > 0 && subarea < 5)
                        subarea = 5;
                    if (subarea < 0)
                        subarea = 0;
                    lblsubdetail.Text = "<span style='color:red'>租金补贴</span>：<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                    lblsubdetail.Text += "补贴建筑面积=" + onlyonearea + "-总建筑面积";
                    lblsubdetail.Text += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;补贴建筑面积：" + onlyonearea + "-" + totlearea + "=<span style='font-size:14px;color:blue'>" + subarea.ToString("0") + "平方米</span>&nbsp;&nbsp;&nbsp;&nbsp;";
                }
                else
                {
                    subarea = ispronum * homeavgarea - ((totlearea / peoplenum) * ispronum);
                    if (subarea > 0 && subarea < 5)
                        subarea = 5;
                    if (subarea < 0)
                        subarea = 0;
                    lblsubdetail.Text = "<span style='color:red'>租金补贴</span>：<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                    lblsubdetail.Text += "补贴建筑面积=保障人口×" + homeavgarea + "-(总建筑面积/家庭人口)*保障人口<br/>";
                    lblsubdetail.Text += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;补贴建筑面积：" + ispronum + "*" + homeavgarea + "-(" + totlearea + "/" + peoplenum + ")*" + ispronum + "=<span style='font-size:14px;color:blue'>" + subarea.ToString("0") + "平方米</span><br/>";
                }
                if (doctype == "最低收入家庭" || doctype == "其他家庭")
                {
                    submoney = subarea * otherrentstandard;
                    lblsubdetail.Text += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;月补贴金额=补贴建筑面积*租金补贴标准<br/>";
                    lblsubdetail.Text += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;月补贴金额：" + subarea + "*" + otherrentstandard + "=<span style='font-size:14px;color:blue'>" + submoney.ToString("0") + "元</span>";
                }
                else
                {
                    submoney = subarea * lowrentstandard;
                    lblsubdetail.Text += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;月补贴金额=补贴建筑面积*租金补贴标准<br/>";
                    lblsubdetail.Text += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;月补贴金额：" + subarea + "*" + lowrentstandard + "=<span style='font-size:14px;color:blue'>" + submoney.ToString("0") + "元</span>";
                }
            }
            ReduceRecord reducerecord = new ReduceRecord();
            reducerecord.GetNewestReduceRecordBynoid(lblnoid.Text);
            if (reducerecord.Adj_stoptime != null)
            {
                lblreddetail.Text = "<span style='color:red'>租金减免</span>：<br/>";
                lblreddetail.Text += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;承租人：" + reducerecord.Adj_renter;
                lblreddetail.Text += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;承租地址：" + reducerecord.Adj_rentaddress;
                lblreddetail.Text += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;住房计租面积：" + reducerecord.Adj_nowarea + "平方米<br/>";
                lblreddetail.Text += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;核定月金额：" + reducerecord.Adj_nowmoney + "元";
                lblreddetail.Text += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;月减免金额：" + reducerecord.Adj_nowreduce + "元";
                lblreddetail.Text += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;有效期：" + reducerecord.Adj_stoptime.Substring(0, 4) + "年" + reducerecord.Adj_stoptime.Substring(4, 2) + "月";
            }
            KindRecord kindrecord = new KindRecord();
            kindrecord.GetNewestKindRecordBynoid(lblnoid.Text);
            if (kindrecord.Adj_stoptime != null)
            {
                lblkinddetail.Text = "<span style='color:red'>实物配租</span>：<br/>";
                lblkinddetail.Text += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;房屋座落：" + kindrecord.Adj_location;
                lblkinddetail.Text += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;建筑面积：" + kindrecord.Adj_nowarea + "平方米";
                lblkinddetail.Text += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;使用面积：" + kindrecord.Adj_nowuserarea + "平方米";
                lblkinddetail.Text += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;有效期：" + kindrecord.Adj_stoptime.Substring(0, 4) + "年" + kindrecord.Adj_stoptime.Substring(4, 2) + "月";
            }
        }
        btnunpass.Attributes.Add("onclick","return confirm('真的要否决吗？')");
    }
    protected void btnunpass_Click(object sender, EventArgs e)
    {
        bool fail = apply.SetApplyUnPass(lblnoid.Text);
        if (fail)
            WebHelper.AlertAndCloseThenRefreshLastPage("该申请单已被否决！");
        else
            WebHelper.Alert("否决不通过，请重新操作");
    }
    protected void btnpass_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(txbdate.Text))
        {
            AreaCheck areacheck = new AreaCheck();
            bool succAddAreaCheck = areacheck.AddAreaCheck(lblnoid.Text, txbname.Text, txbreponsname.Text, txbdate.Text);
            if (succAddAreaCheck)
            {
                bool succAddOne = apply.SetCheckStateAddOne(lblnoid.Text);
                if (succAddOne)
                    WebHelper.AlertAndCloseThenRefreshLastPage("审核成功，请继续其他操作！");
                else
                    WebHelper.Alert("审核失败，请重新操作");
            }
            else
                WebHelper.Alert("已审核或审核失败！");
        }
        else
            WebHelper.Alert("请填写审核日期");
    }
}
